package com.wanshu.service.impl;

import com.wanshu.dao.TaskDao;
import com.wanshu.entity.Task;
import com.wanshu.service.TaskService;
import com.wanshu.util.ResultUtil;

import java.util.List;

public class TaskServiceImpl implements TaskService {

    private TaskDao taskDao;

    public void setTaskDao(TaskDao taskDao) {
        this.taskDao = taskDao;
    }

    public String receiveTask(Task task){
        Integer update = taskDao.update(task);
        if(update > 0){
            return "领取任务成功!";
        }else{
            return "领取失败!";
        }
    }

    public String insert(Task task){
        Integer insert = taskDao.insert(task);
        if(insert > 0){
            return ResultUtil.success("添加任务成功!",insert);
        }else{
            return ResultUtil.fail("添加任务失败!",insert);
        }
    }

    @Override
    public Integer update(Task task) {
        return null;
    }

    public String delete(Integer id){
        Integer delete = taskDao.delete(id);
        String msg = "删除失败";
        if(delete > 0){
            msg = "删除成功!";
        }
        return msg;
    }

    public List<Task> findAll(){
        return taskDao.findAll();
    }

    @Override
    public Task findById(Integer id) {
        return null;
    }
}
